//
//  MyTermBonudsCell.m
//  HuaMuJinRong
//
//  Created by 吴建东 on 16/4/21.
//  Copyright © 2016年 EIMS. All rights reserved.
//

#import "MyTermBonudsCell.h"

@interface MyTermBonudsCell ()
{
    MyTermBonudsModel *_model;
}
@end

@implementation MyTermBonudsCell

- (void)awakeFromNib {
    // Initialization code
    [super awakeFromNib];
    _titleLabel.font = KFontSize(14.0);
    _timeLabel.font = KFontSize(13);
    _waitingProfitLabel.font = KFontSize(16);
    _waitingProfitValue.font = KFontSize(13);
    _princalLabel.font = KFontSize(16);
    _princalValue.font = KFontSize(13);
    _detailValue.font = KFontSize(14.0);
    _timeLabel.adjustsFontSizeToFitWidth = YES;
    _waitingProfitLabel.adjustsFontSizeToFitWidth = YES;
    _princalLabel.adjustsFontSizeToFitWidth = YES;
    
    _progressView = [[RMDownloadIndicator alloc] initWithFrame:RECTMAKE(KAdaptNum(240), GetMinY(_waitingProfitLabel), KAdaptNum(50), KAdaptNum(50)) type:kRMClosedIndicator];
    [_progressView setBackgroundColor:[UIColor clearColor]];
    [_progressView setFillColor:KbackgroundColor];
    [_progressView setStrokeColor:KColor];
    [_progressView loadIndicator];
    [self addSubview:_progressView];
    
    _leftDayLabel = [UILabel labelWithFrame:RECTMAKE(5, 5, GetWidth(_progressView) - 10, KAdaptNum(20)) text:@"" textColor:KColor textFont:14 fitWidth:YES superview:_progressView];
    _leftDayLabel.textAlignment = NSTextAlignmentCenter;
    _leftDayLabel.hidden = YES;
    
    _leftDayValue = [UILabel labelWithFrame:RECTMAKE(5, GetMaxY(_leftDayLabel), GetWidth(_progressView) - 10, KAdaptNum(20)) text:@"剩余(天)" textColor:KColor textFont:10 fitWidth:YES superview:_progressView];
    _leftDayValue.textAlignment = NSTextAlignmentCenter;
    _leftDayValue.hidden = YES;
    
    _stausLabel = [UILabel labelWithFrame:RECTMAKE(0, 0, GetWidth(_progressView), GetHeight(_progressView)) text:@"" textColor:KColor textFont:12 fitWidth:YES superview:_progressView];
    _stausLabel.textAlignment = NSTextAlignmentCenter;
    _stausLabel.hidden = YES;
}

- (void)refreshCellWithModel:(MyTermBonudsModel *)model {
    
    _model = model;
    _titleLabel.text = model.title;
    _timeLabel.text = model.investTime;
    _waitingProfitLabel.text = [CommonClass formatConversion:model.receive_interest type:0];
    _princalLabel.text = [CommonClass formatConversion:model.amount type:0];
   
    _leftDayLabel.hidden = YES;
    _leftDayValue.hidden = YES;
    _stausLabel.hidden = NO;
    [_progressView updateWithTotalBytes:1.0 downloadedBytes:1.0];
    
    switch (model.status) {
        case 0:
        {
            NSDate *todayDate = [NSDate date];
            NSDateFormatter *todayDateFormat = [[NSDateFormatter alloc] init];
            
            [todayDateFormat setDateFormat:@"yyyy-MM-dd HH:mm"];
            NSString *today = [todayDateFormat stringFromDate:todayDate];
            
            if ([today isEqualToString:model.lastRepayTime]) {
                _stausLabel.text = @"结算中";

            }else {
                _leftDayLabel.hidden = NO;
                _leftDayValue.hidden = NO;
                _stausLabel.text = @"";
                _stausLabel.hidden = YES;
                
                [_progressView updateWithTotalBytes:1.0 downloadedBytes:((double)model.left_day)/(model.period*30.0)];
                _leftDayLabel.text = [NSString stringWithFormat:@"%ld",(long)model.left_day];
            }
        }
            break;
        case 1:
            _stausLabel.text = @"已完成";
            break;
            
        default:
            _stausLabel.text = @"募集中";
            
            break;
    }
    
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    _progressView.frame = RECTMAKE(KAdaptNum(245), GetMinY(_waitingProfitLabel), KAdaptNum(50), KAdaptNum(50));
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
